import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('cart', () => {
  let piniaCart = ref([])
  let piniaAddCart = (detail, goods_id) => {
    let pdcart = piniaCart.value.find(item => item.goods_id == goods_id)
    if (pdcart) {
      pdcart.number++
    }
    else {
      piniaCart.value.push({
        username: localStorage.getItem('username'),
        number: 1,
        goods: detail,
        checked: false,
        id: Math.floor(Math.random() * 100000)
      })
    }
  }
  return { piniaCart, piniaAddCart }
},
  {
    persist: true,
  },
)
